Skip to content

Conversation

@kanadgupta
Copy link
Member

@kanadgupta kanadgupta commented Sep 17, 2025

🚥 Resolves CX-1793

🧰 Changes

expanding on the work from #1344, this PR tweaks a bunch of logic / DX improvements to better account for the following rdme openapi upload edge cases:

  • URL uploads that lack a path but have a custom slug with a JSON file extension (e.g., rdme openapi upload https://example.com --custom-slug.json) will now properly read that file and set that slug
  • URL uploads that lack a path but have a custom slug with a YAML file extension (e.g., rdme openapi upload https://example.com --custom-slug.yml) will now properly read that file and set that slug
  • URL uploads that lack a path and there's no --slug passed (e.g., rdme openapi upload https://example.com) will now default to openapi.json and emit a warning about this behavior
  • URL uploads with a path that lacks a file extension and there's no --slug passed (e.g., rdme openapi upload https://example.com/some-path) will now properly handle JSON/YAML and set the slug to that path (e.g., some-path.json). [applicable for both creates and updates]

🧬 QA & Testing

honestly the more test cases i added, the more rework i realized this logic required 😮‍💨 the fact that they're passing brings me a lot of comfort here lol

@kanadgupta kanadgupta changed the title fix(openapi/upload): more edge case handling for URLs with no pathnames fix(openapi/upload): more edge case handling for URL uploads Sep 17, 2025
@kanadgupta kanadgupta added command:openapi Issues pertaining to the `openapi`, `validate`, `reduce`, or `swagger` commands bug Something isn't working labels Sep 20, 2025
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the diff in this file is pretty rough apologies 😭 i had to shuffle a bit of logic around to hit all of these edge cases and tried to simplify logic and add comments wherever i could. might be easier to just read the file top-to-bottom to be honest 😮‍💨

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other than the new tests, the other test refactors are either stricter assertions or minor variable renaming!

@kanadgupta kanadgupta marked this pull request as ready for review September 20, 2025 01:13
Copy link
Member

@emilyskuo emilyskuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one non-blocking question. Otherwise looks good!


const fileExtension = nodePath.extname(filename) || '.json'; // default to .json if no extension is found
const fileExtension = nodePath.extname(filename);
const isFileYaml = yamlExtensions.includes(fileExtension);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to determine if the file is yaml besides reading the file extension? It seems a little odd to coerce it into json if a url doesn't have a file extension and we don't have a slug (as asserted in the test should create a new API definition in ReadMe if there is no path and the file is YAML)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there isn't an easy way to do this, I think defaulting to openapi.json is fine

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's a very good question... so oas-normalize is what processes this file (e.g., fetches the URL, converts the file to JSON, validates/bundles it, etc.) and there's a bit of a limitation with URL uploads where we only delineate the file type for local files and not for URLs (see the screenshot of the oas-normalize type parameter below and note how string-yaml and string-json are a thing, but it's just url and not url-json/url-yaml).

CleanShot 2025-10-08 at 16 35 25@2x

my thinking is that if someone passes in a URL and the URL end with a file extension and the user is not passing a slug, we can safely just fallback to assuming it's JSON and call it a day. if they feel otherwise, they can very easily set a slug 🤷🏽 i'm open to fixing this at an oas-normalize level if this becomes a problem that customers complain about, but my hope is that it's an edge case we'll rarely run into!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you did inspire me to revisit this and i made a small tweak in 59b5637 that should be fairly harmless!

unlikely we'll hit this since this really only affects local YAML files that do not have a file extension... but sure why not!
@kanadgupta kanadgupta merged commit 76e60b3 into next Oct 8, 2025
9 checks passed
@kanadgupta kanadgupta deleted the kanad-2025-09-17/more-URL-uploading-quirks branch October 8, 2025 23:47
kanadgupta pushed a commit that referenced this pull request Oct 8, 2025
## [10.5.4-next.1](v10.5.3...v10.5.4-next.1) (2025-10-08)

### Bug Fixes

* **openapi/upload:** more edge case handling for URL uploads ([#1348](#1348)) ([76e60b3](76e60b3))

[skip ci]
@kanadgupta
Copy link
Member Author

🎉 This PR is included in version 10.5.4-next.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working command:openapi Issues pertaining to the `openapi`, `validate`, `reduce`, or `swagger` commands released on @next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants